package java8;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/7/19 21:04
 */
public class TestStreamAPI {
    List<Employee> employees = Arrays.asList(
            new Employee("张三", 18, 9999.99, Employee.Status.FREE),
            new Employee("李四", 38, 5555.555, Employee.Status.BUSY),
            new Employee("王五", 50, 6666.66, Employee.Status.VOCATION),
            new Employee("赵柳", 16, 3333.33, Employee.Status.FREE),
            new Employee("田七", 8, 7777.77, Employee.Status.BUSY));

    /**
     * 给定一组数字列表，返回数字平方的列表
     */
    @Test
    public void test1() {
        Integer[] nums = new Integer[]{1, 2, 3, 4, 6, 5, 5, 7, 8};
        Arrays.stream(nums).map(x -> x * x).forEach(System.out::println);
    }

    /**
     * 用map和reduce查询employee的个数
     */
    @Test
    public void test2(){
        Optional<Integer> sum = employees.stream().map(e->1).reduce(Integer::sum);
        System.out.println(sum.get());
    }
}
